<?php

namespace api\mm\service;
/*
 * Edit by shengxin
 * Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/PHPClass.php to edit this template
 */
use GuzzleHttp\Client;
/**
 * Description of HostReqest
 *
 * @author PC
 */
class HostReqest {
    
    private $token = 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxNTYwNDA4MTA5MyIsImF1dGhvcml0aWVzIjoiIiwiZXhwIjoxODAxNTI4NjAzfQ.-oZaJaYAX6HheKNJbIUty1ZiKTL7LkVM6SIJrasYUpWZBSMUmUopvmKYEw7ZeMCNYWnS4jOc7XFoUyxqWBjeRQ';
    public function get($api,$params=[]){
        $client = new Client([
              'base_uri'        => 'http://app.3985.site',
              'timeout'         => 0,
            'headers'=>[
                'User-Agent'=>'okhttp/4.9.1',
                'Authorization'=>$this->token
            ],
             'allow_redirects' => false,
         ]);
        $resp = $client->get($api,$params);
        if($resp->getStatusCode()==200){
            $body = (string)$resp->getBody();
            $data = json_decode($body,true);
            return $data;
        }
    }
    
    public function post($api,$data){
        $client = new Client([
              'base_uri'        => 'http://app.3985.site',
              'timeout'         => 0,
            'headers'=>[
                'User-Agent'=>'okhttp/4.9.1',
                'Authorization'=>$this->token
            ],
             'allow_redirects' => false,
         ]);
        $resp = $client->post($api,['json'=>$data]);
        if($resp->getStatusCode()==200){
            $body = (string)$resp->getBody();
            $data = json_decode($body,true);
            return $data;
        }
    }
    
    public function studentList(){
        /**
         * GET /stu-mob-mon-customer/api/v1/parents/studentList HTTP/1.1
Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxNTYwNDA4MTA5MyIsImF1dGhvcml0aWVzIjoiIiwiZXhwIjoxODAxNTI4NjAzfQ.-oZaJaYAX6HheKNJbIUty1ZiKTL7LkVM6SIJrasYUpWZBSMUmUopvmKYEw7ZeMCNYWnS4jOc7XFoUyxqWBjeRQ
Host: app.3985.site
Connection: Keep-Alive
User-Agent: okhttp/4.9.1
         */
        $api = '/stu-mob-mon-customer/api/v1/parents/studentList';
        return $this->get($api);
    }
    
    public function getStudentStatus($studentId){
        //GET /stu-mob-mon-customer/api/v1/deviceStatus/getStudentStatus?studentId=07d51f5d1577423ca1d82a570ee34fd9 HTTP/1.1
        $api = 'stu-mob-mon-customer/api/v1/deviceStatus/getStudentStatus';
        return $this->get($api,['query' => ['studentId' => $studentId]]);
    }
    
    public function statistics($studentId,$date){
        //GET /stu-mob-mon-customer/api/v1/appRecords/statistics?type=1&studentId=07d51f5d1577423ca1d82a570ee34fd9&date=2024-05-08 HTTP/1.1
        $api = 'stu-mob-mon-customer/api/v1/appRecords/statistics';
        return $this->get($api,['query' => ['studentId' => $studentId,'type'=>1,'date'=>$date]]);
    }
    
    public function statistics_week($studentId,$date){
        //GET /stu-mob-mon-customer/api/v1/appRecords/statistics?type=1&studentId=07d51f5d1577423ca1d82a570ee34fd9&date=2024-05-08 HTTP/1.1
        $api = 'stu-mob-mon-customer/api/v1/appRecords/statistics';
        return $this->get($api,['query' => ['studentId' => $studentId,'type'=>2,'date'=>$date]]);
    }
    
    /**
     * 查询每日允许使用手机时长
     */
    public function queryAvailableTime($studentId){
        /**
POST /stu-mob-mon-customer/api/v2/patternParents/queryControlSwitchAndAvailableTime HTTP/1.1
Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxNTYwNDA4MTA5MyIsImF1dGhvcml0aWVzIjoiIiwiZXhwIjoxODAxNTI4NjAzfQ.-oZaJaYAX6HheKNJbIUty1ZiKTL7LkVM6SIJrasYUpWZBSMUmUopvmKYEw7ZeMCNYWnS4jOc7XFoUyxqWBjeRQ
Content-Type: application/json
Host: app.3985.site
Connection: Keep-Alive
User-Agent: okhttp/4.9.1
Accept-Encoding: gzip, deflate
Content-Length: 48

{"studentId":"88f0f5f580f34753bd1f56978f4c8a1f"}
         */
        $data = [
           'studentId'=>$studentId 
        ];
        return $this->post('stu-mob-mon-customer/api/v2/patternParents/queryControlSwitchAndAvailableTime', $data);
    }
    
    public function setAvailableTime($data){
        ///stu-mob-mon-customer/api/v2/patternParents/settingAvailableTime HTTP/1.1
        //{"studentId":"07d51f5d1577423ca1d82a570ee34fd9","weekendAvailableTime":185,"dailyAvailableTime":125,"type":1,"dailyAvailableTimeName":"2小时5分钟","weekendAvailableTimeName":"3小时5分钟"}
        return $this->post('stu-mob-mon-customer/api/v2/patternParents/settingAvailableTime', $data);
    }
    
    public function set(){
//        POST /stu-mob-mon-customer/api/v2/patternParents/settingAvailableTime HTTP/1.1
//        Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxNTYwNDA4MTA5MyIsImF1dGhvcml0aWVzIjoiIiwiZXhwIjoxODAxNTI4NjAzfQ.-oZaJaYAX6HheKNJbIUty1ZiKTL7LkVM6SIJrasYUpWZBSMUmUopvmKYEw7ZeMCNYWnS4jOc7XFoUyxqWBjeRQ
//        Content-Type: application/json
//        Host: app.3985.site
//        Connection: Keep-Alive
//        User-Agent: okhttp/4.9.1
//        Accept-Encoding: gzip, deflate
//        Content-Length: 150

//{"studentId":"07d51f5d1577423ca1d82a570ee34fd9","weekendAvailableTime":-1,"dailyAvailableTime":125,"type":1,"dailyAvailableTimeName":"2小时5分钟"}
    }
}
